package com.groupbuying.customerconsumer.service.impl;

import com.groupbuying.customerconsumer.constants.CommonConstants;
import com.groupbuying.customerconsumer.constants.CustomerUshopSearchConstants;
import com.groupbuying.customerconsumer.dao.CustomerUshopDao;
import com.groupbuying.customerconsumer.domain.CustomerUshopDO;
import com.groupbuying.customerconsumer.service.CustomerUshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CustomerUshopServiceImpl implements CustomerUshopService {
	@Autowired
	private CustomerUshopDao customerUshopDao;
	@Autowired
	private CustomerUshopService customerUshopService;
	
	@Override
	public CustomerUshopDO get(String customerId){
		return customerUshopDao.get(customerId);
	}
	
	@Override
	public List<CustomerUshopDO> list(Map<String, Object> map){
		return customerUshopDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return customerUshopDao.count(map);
	}
	
	@Override
	public int save(CustomerUshopDO customerUshop){
		return customerUshopDao.save(customerUshop);
	}
	
	@Override
	public int update(CustomerUshopDO customerUshop){
		return customerUshopDao.update(customerUshop);
	}
	
	@Override
	public int remove(String customerId){
		return customerUshopDao.remove(customerId);
	}
	
	@Override
	public int batchRemove(String[] customerIds){
		return customerUshopDao.batchRemove(customerIds);
	}

	@Override
 	public CustomerUshopDO getUshopInfoByMobile(String mobile){
		Map searchMap = new HashMap();
		searchMap.put(CustomerUshopSearchConstants.SEARCH_MOBILE, mobile);
		searchMap.put(CustomerUshopSearchConstants.SEARCH_ISDELETE, CommonConstants.COMMON_FLAG_UNDEL);
		List<CustomerUshopDO> customerUshopDOList = customerUshopService.list(searchMap);
		if(customerUshopDOList == null || customerUshopDOList.size() == 0){
			return null;
		}
		return customerUshopDOList.get(0);
	}

	@Override
	public CustomerUshopDO getUshopInfoByMainUuid(String mainUuid){
		Map searchMap = new HashMap();
		searchMap.put(CustomerUshopSearchConstants.SEARCH_MAINUUID, mainUuid);
		searchMap.put(CustomerUshopSearchConstants.SEARCH_ISDELETE, CommonConstants.COMMON_FLAG_UNDEL);
		List<CustomerUshopDO> customerUshopDOList = customerUshopService.list(searchMap);
		if(customerUshopDOList == null || customerUshopDOList.size() == 0){
			return null;
		}
		return customerUshopDOList.get(0);
	}

	@Override
	public boolean checkMobileExist(String mobile){
		if(this.getUshopInfoByMobile(mobile) == null){
			return false;
		}
		return true;
	}
}
